<template>
  <div class="head"></div>
  <div class="body">
    <h3 ref="storeRef">{{ storeCount }}</h3>
    <el-button type="primary" @click="dialogFormVisible = true">添加</el-button>
    <el-input v-model="filterName" placeholder="请输入名称"></el-input>
    <h4>结果集包含姓张的个数：{{ nameCount }}</h4>
    <el-table :data="tableData" border style="width: 100%">
      <el-table-column prop="id" label="id"> </el-table-column>
      <el-table-column prop="name" label="姓名"> </el-table-column>
      <el-table-column prop="birth" label="生日"> </el-table-column>
      <el-table-column label="操作">
        <template #default="scope">
          <el-button @click="edit(scope.row)" type="text">编辑</el-button>
          <el-button @click="del(scope.row.id)" type="text">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="pageSizeChange"
      @current-change="pageCurrentChange"
      :current-page="pageNum"
      :page-sizes="[10, 20, 30, 40]"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="totalNum"
    >
    </el-pagination>
  </div>
  <div class="bottom"></div>
  <el-dialog title="人员档案" v-model="dialogFormVisible" @close="cancel">
    <el-form :model="form">
      <el-form-item label="名称">
        <el-input v-model="form.name" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="生日">
        <el-input v-model="form.birth" autocomplete="off"></el-input>
      </el-form-item>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="save">确 定</el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script>
import commonPageRepository from "@/composables/common-page-repository";
import homeRepository from "@/composables/home-repository";

export default {
  name: "Home",
  setup() {
    const {
      id,
      tableData,
      filterName,
      pageSize,
      pageNum,
      totalNum,
      form,
      dialogFormVisible,
      nameCount,
      storeCount,
      get,
      del,
      save,
      edit,
      cancel,
      storeRef,
    } = homeRepository();

    const { pageSizeChange, pageCurrentChange } = commonPageRepository(
      pageSize,
      pageNum,
      get
    );
    return {
      id,
      tableData,
      filterName,
      pageSize,
      pageNum,
      totalNum,
      form,
      dialogFormVisible,
      nameCount,
      storeCount,
      get,
      del,
      save,
      edit,
      cancel,
      pageSizeChange,
      pageCurrentChange,
      storeRef,
    };
  },
};
</script>
<style>
.a {
  position: relative;
}
</style>
